<?php

JLoader::register("PCompanyModelSubAccounts", OC_App::getAppPath('company') . "/lib/subaccounts.php");

$LoginStats = PUtil::checkUserLogin(true);
if ($LoginStats !== true) {
   echo $LoginStats;
   exit();
}

$l = OC_L10N::get('company');
OCP\JSON::callCheck();

if(!PFactory::isMasterUser()) {
   OC_JSON::error(array('data' => array( 'message' => '您无权访问该资源')));
   exit;
}

$uid = JRequest::getString("uid", "");

// Return Success story
try {
   if(!PSession::checkToken('post')) {
      OC_JSON::error(array('data' => array( 'message' => '登录已失效，请重新登录')));
      exit;
   }

   $model = new PCompanyModelSubAccounts; 

   if (!$model->removeUser($uid)) {
      OC_JSON::error(array("data" => array( "message" => "删除子账号失败！")));
      exit;
   }

   OC_JSON::success();
} catch (Exception $exception) {
   OC_JSON::error(array("data" => array( "message" => $l->t($exception->getMessage()))));
}
